package com.java.web;

import com.java.dao.userDao;
import com.java.dao.userDaoImpl;
import com.java.doMain.user;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author xyd
 * @Date 2021/12/23 19:27
 * @Version 1.0
 */
public class payServlet extends HttpServlet {

    private userDao userDao = new userDaoImpl();

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        user user = (com.java.doMain.user) request.getSession().getAttribute("user");
        String money = request.getParameter("money");
        double v = Double.parseDouble(money);
        user user1 = userDao.selectByUsername(user.getUsername());
        double m = user1.getBalance()-v;
        userDao.updateMoney(user.getUserID(),m);
        request.getSession().setAttribute("user",userDao.selectByUsername(user1.getUsername()));
        request.getRequestDispatcher(request.getContextPath() + "/client/myAccount.jsp").forward(request,response);
    }
}
